package com.example.javaee.mapper;

import com.example.javaee.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    @Results(id = "orderMap", value = {
            @Result(property = "订单编号", column = "订单编号"),
            @Result(property = "菜品编号", column = "菜品编号"),
            @Result(property = "菜品名", column = "菜品名"),
            @Result(property = "消费额", column = "消费额")
    })
    @Select("SELECT * FROM 订单信息表")
    List<Order> findAll();

    @Select("SELECT * FROM 订单信息表 WHERE 订单编号 LIKE CONCAT('%', #{keyword}, '%') " +
            "OR 菜品名 LIKE CONCAT('%', #{keyword}, '%')")
    List<Order> search(String keyword);

    @Insert("INSERT INTO 订单信息表(订单编号, 菜品编号, 菜品名, 消费额) " +
            "VALUES(#{订单编号}, #{菜品编号}, #{菜品名}, #{消费额})")
    int insert(Order order);

    @Update("UPDATE 订单信息表 SET 菜品编号=#{菜品编号}, 菜品名=#{菜品名}, " +
            "消费额=#{消费额} WHERE 订单编号=#{订单编号}")
    int update(Order order);

    @Delete("DELETE FROM 订单信息表 WHERE 订单编号=#{订单编号}")
    int delete(String 订单编号);
}
